#include<iostream>
#include<string>
#include"contacts.pb.h"
using namespace std;

int main()
{
    contacts::PeopleInfo people;
    string peoplestr;
    //序列化
   {
    people.set_name("张三");
    people.set_age(18);
    if(!people.SerializeToString(&peoplestr))
    {
        cerr<<"序列化错误！"<<endl;
        return -1;
    }
   }
   //反序列化
   {
     contacts::PeopleInfo people_s;
     if(!people_s.ParseFromString(peoplestr))
     {
        cerr<<"反序列化错误！"<<endl;
        return -1;
     }
     cout<<"序列化成功："<<endl;
     cout<<"name: "<<people_s.name()<<endl;
     cout<<"age: "<<people_s.age()<<endl;
   }
    return 0;
}